<template>
  <div>
    <el-dialog
      :title="flag ? '编辑标签' : '新增标签'"
      :visible.sync="dialogVisible"
      width="40%"
      @close="cancel"
    >
      <div>
        <el-form ref="formdata" :model="form" label-width="80px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="业务类型" prop="businessType">
                <el-select
                  v-model="form.businessType"
                  placeholder="选择业务类型"
                  size="small"
                  clearable
                  filterable
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in businessTypelist"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="所属企业" prop="orgNo">
                <el-select
                  v-model="form.orgNo"
                  placeholder="选择业务类型"
                  size="small"
                  clearable
                  filterable
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.orgNo"
                    :label="item.orgName"
                    :value="item.orgNo"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="标签编号" prop="labelId">
                <el-input
                  v-model="form.labelId"
                  size="small"
                  placeholder="请输入标签编号"
                  :disabled="flag"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="标签名称" prop="labelName">
                <el-input
                  v-model="form.labelName"
                  size="small"
                  placeholder="请输入标签名称"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="标签描述" prop="labelDesc">
                <el-input type="textarea" v-model="form.labelDesc"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="维护日期" prop="maintainDate">
                <el-date-picker
                  style="width: 100%"
                  v-model="form.maintainDate"
                  size="small"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="标签状态" prop="labelStatus">
                <el-select
                  v-model="form.labelStatus"
                  placeholder="选择标签状态"
                  size="small"
                  style="width: 100%"
                >
                  <el-option label="启用" value="1"></el-option>
                  <el-option label="停用" value="0"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="save" size="small">保 存</el-button>
        <el-button @click="cancel" size="small">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  postaddbiaoqianapi,
  postupdatebiaoqianapi
} from '@/api/system/labelManage'
export default {
  name: 'CallPoliceDialog',
  props: {
    options: {
      type: Array
    }
    // businessTypelist: {
    //   type:Array
    // }
  },
  data() {
    return {
      flag: false,
      form: {},
      dialogVisible: false,
      businessTypelist: [
        { name: '配电管理', value: '01' },
        { name: '能耗管理', value: '02' },
        { name: '光伏管理', value: '03' },
        { name: '微电网管理', value: '04' },
        { name: '计费管理', value: '05' }
      ]
    }
  },

  async mounted() {},

  methods: {
    // 保存
    async save() {
      this.flag
        ? await postupdatebiaoqianapi(this.form).then((res) => {
            this.$message({
              type: res.code == 200 ? 'success' : 'warning',
              message: res.code == 200 ? '编辑成功' : res.message
            })
            if (res.code == 200) this.cancel()
            if (res.code == 200) this.$emit('togetlist')
          })
        : await postaddbiaoqianapi(this.form).then((res) => {
            this.$message({
              type: res.code == 200 ? 'success' : 'warning',
              message: res.code == 200 ? '新增成功' : res.message
            })
            if (res.code == 200) this.cancel()
            if (res.code == 200) this.$emit('togetlist')
          })
    },
    //编辑
    toupdate(item) {
      this.flag = true
      this.form = { ...item }
      this.dialogVisible = true
    },
    //取消
    cancel() {
      // this.$nextTick(() => this.$refs.formdata.resetFields())
      this.form = {}
      this.dialogVisible = false
      this.flag = false
    }
  },
  watch: {
    dialogVisible(val) {
      if (!val) {
        this.cancel()
      }
    }
  }
}
</script>
<style scoped>
::v-deep .el-dialog__footer {
  text-align: center;
}
</style>
